package redis

import (
	"fmt"
	"github.com/gomodule/redigo/redis"
)

func Zadd(score int, userName string, rankName string) {
	c := pool.Get()
	defer c.Close()
	_, err := c.Do("ZADD", rankName, "INCR", score, userName)
	if err != nil {
		fmt.Print(err)
		return
	}
}
func Zrevrange(gameName string) {
	connect := pool.Get()
	defer connect.Close()
	r, err := redis.Bytes(connect.Do("zrevrange", gameName, 0, 10))
	if err != nil {
		return
	}
	println(r)
	return
}
func Zrevrank(gameName, id string) int {
	connect := pool.Get()
	defer connect.Close()
	r, err := redis.Int(connect.Do("zrevrank", gameName, id))
	if err != nil {
		return 0
	}
	println(r)
	return r + 1
}
func Zrank(gameName, id string) int {
	connect := pool.Get()
	defer connect.Close()

	index, err := redis.Int(connect.Do("zrank", gameName, id))
	if err != nil {
		fmt.Print(err)
		return 0
	}
	return index
}

func Zscore(gameName, id string) int {
	connect := pool.Get()
	defer connect.Close()
	r, err := redis.Int(connect.Do("zscore", gameName, id))
	if err != nil {
		fmt.Print(err)
		return 0
	}
	println(r)
	return r
}
func Zrem(gameName, id string) {
	connect := pool.Get()
	defer connect.Close()
	_, err := redis.Bytes(connect.Do("ZREM", gameName, id))
	if err != nil {
		fmt.Print(err)
		return
	}
}
